{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "import plotly.graph_objs as go\n",
    "\n",
    "df = pd.read_csv('../data/yield_curve.csv')\n",
    "xlist = list(df[\"x\"].dropna())\n",
    "ylist = list(df[\"y\"].dropna())\n",
    "\n",
    "del df[\"x\"]\n",
    "del df[\"y\"]\n",
    "\n",
    "zlist = []\n",
    "for row in df.iterrows():\n",
    "    index, data = row\n",
    "    zlist.append(data.tolist())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "z_secondary_beginning = [z[1] for z in zlist if z[0] == \"None\"]\n",
    "z_secondary_end = [z[0] for z in zlist if z[0] != \"None\"]\n",
    "z_secondary = z_secondary_beginning + z_secondary_end\n",
    "x_secondary = [\"3-month\"] * len(z_secondary_beginning) + [\"1-month\"] * len(\n",
    "    z_secondary_end\n",
    ")\n",
    "y_secondary = ylist\n",
    "\n",
    "trace1 = dict(\n",
    "    type=\"surface\",\n",
    "    x=xlist,\n",
    "    y=ylist,\n",
    "    z=zlist,\n",
    "    hoverinfo=\"x+y+z\",\n",
    "    lighting={\n",
    "        \"ambient\": 0.95,\n",
    "        \"diffuse\": 0.99,\n",
    "        \"fresnel\": 0.01,\n",
    "        \"roughness\": 0.01,\n",
    "        \"specular\": 0.01,\n",
    "    },\n",
    "    colorscale=[\n",
    "        [0, \"rgb(230,245,254)\"],\n",
    "        [0.4, \"rgb(123,171,203)\"],\n",
    "        [0.8, \"rgb(40,119,174)\"],\n",
    "        [1, \"rgb(37,61,81)\"],\n",
    "    ],\n",
    "    opacity=0.7,\n",
    "    showscale=False,\n",
    "    scene=\"scene\",\n",
    ")\n",
    "\n",
    "trace2 = dict(\n",
    "    type=\"scatter3d\",\n",
    "    mode=\"lines\",\n",
    "    x=x_secondary,\n",
    "    y=y_secondary,\n",
    "    z=z_secondary,\n",
    "    hoverinfo=\"x+y+z\",\n",
    "    line=dict(color=\"#444444\"),\n",
    ")\n",
    "\n",
    "data = [trace1, trace2]\n",
    "layout = dict(\n",
    "    autosize=True,\n",
    "    font=dict(size=12, color=\"#CCCCCC\"),\n",
    "    margin=dict(t=5, l=5, b=5, r=5),\n",
    "    showlegend=False,\n",
    "    hovermode=\"closest\",\n",
    "    scene=dict(\n",
    "        aspectmode=\"manual\",\n",
    "        aspectratio=dict(x=2, y=5, z=1.5),\n",
    "        xaxis={\n",
    "            \"showgrid\": True,\n",
    "            \"title\": \"\",\n",
    "            \"type\": \"category\",\n",
    "            \"zeroline\": False,\n",
    "            \"categoryorder\": \"array\",\n",
    "            \"categoryarray\": list(reversed(xlist)),\n",
    "        },\n",
    "        yaxis={\"showgrid\": True, \"title\": \"\", \"type\": \"date\", \"zeroline\": False},\n",
    "    ),\n",
    ")\n",
    "figure = dict(data=data, layout=layout)\n",
    "\n",
    "go.FigureWidget(figure)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
